package com.example.android.ui.mine;

import com.example.android.bean.BaseBean;
import com.example.android.bean.Mine;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class MinePresenter implements MineContract.IMinePresenter {
    MineContract.IMineModel mineModel;
    private MineContract.IMineView mineView;
    public MinePresenter(MineContract.IMineView mineView){
        this.mineView = mineView;
        mineModel = new MineModel();
    }

    @Override
    public void getData() {
        mineModel.getData()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<BaseBean<Mine>>() {
                    @Override
                    public void accept(BaseBean<Mine> mineBaseBean) throws Throwable {
                        mineView.getMineSuccess(mineBaseBean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                        mineView.getMineError(throwable);
                    }
                });
    }
}
